﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Entity;
using Utils.DC.Web.UI;

public partial class Pages_ChangePass : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["loginClient"] != null)
        {
            Customer cus = (Customer)Session["loginClient"];

            if (cus.C_Status)
            {

            }
            else
            {
                Response.Redirect("../Pages/AccountLock.aspx");
            }
        }
        else
        {
            Response.Redirect("../Pages/Login.aspx");
        }
    }


    protected void btnOk_Click(object sender, EventArgs e)
    {
        try
        {
            Customer cusInfo = (Customer)Session["loginClient"];
            Customer cus = new CustomerUI().Login(cusInfo.Username, Security.Encrypt(txtOldPass.Text.Trim()));
            if (cus != null)
            {
                lblError.Visible = false;
                CustomerUI cusUI = new CustomerUI();
                int result = cusUI.ChangePass(cusInfo.Cusid, Security.Encrypt(txtOldPass.Text.Trim()), Security.Encrypt(txtRepass.Text.Trim()));
                if (result > 0)
                {
                    Response.Write("<script>alert('change password successful');</script>");
                }
                else
                {
                    Response.Write("<script>alert('change password fail');</script>");
                }
            }
            else
            {
                lblError.Visible = true;
            }
        }
        catch (Exception ex)
        {

        }
    }
}
